#define _CRT_SECURE_NO_WARNINGS
#include"test.h"
void SLprintf(SL* p)
{
	assert(p);
	assert(p->size);
	for (int i = 0; i < p->size; i++)
	{
		printf("%d ", p->arr[i]);
	}
	printf("\n");
}
void SLinit(SL* p)
{
	assert(p);
	p->arr = NULL;
	p->kong = 0;
	p->size = 0;
}
void SLget(SL* p)
{
	assert(p);
	if (p->arr)
	{
		free(p->arr);
		p->arr = NULL;
	}	
	p->kong = 0;
	p->size = 0;
}

void pan(SL* p)
{
	if (p->kong == p->size)
	{
		int time = p->kong == 0 ? 4 : 2 * p->kong;
		leixing* ass = (leixing*)realloc(p->arr, sizeof(leixing) * time);
		if (ass == NULL)
		{
			perror("realloc ass");
			return 1;
		}
		p->arr = ass;
		p->kong = time;
	}
}
void SLwcha(SL* p, leixing x)
{
	assert(p);
	pan(p);
	p->arr[p->size++] =x;
}
void SLwshan(SL* p)
{
	assert(p);
	assert(p->size);
	p->size--;
}
void SLtcha(SL* p, leixing x)
{
	assert(p);
	pan(p);
	if (p->size != 0)
	{
		for (int i = p->size; i > 0; i--)
		{
			p->arr[i] = p->arr[i - 1];
		}
	}
	p->size++;
	p->arr[0] = x;
}
void SLtshan(SL* p)
{
	assert(p);
	assert(p->size);
	for (int i = 0; i <p->size-1; i++)
	{
		p->arr[i] = p->arr[i + 1];
	}
	p->size--;
}
void SLzcha(SL* p, int wei, leixing x)
{
	assert(p);
	assert(wei <= p->size && wei >= 0);
	pan(p);
	for (int i = p->size; i > wei; i--)
	{
		p->arr[i] = p->arr[i - 1];
	}
	p->arr[wei] = x;
	p->size++;
}
void SLzshan(SL* p, int wei)
{
	assert(p);
	assert(wei <= p->size && wei >= 0);
	for (int i = wei; i < p->size - 1; i++)
	{
		p->arr[i] = p->arr[i + 1];
	}
	p->size--;
}
int SLczao(SL* p, leixing x)
{
	assert(p);
	assert(p->size);
	for (int i = 0; i < p->size; i++)
	{
		if (p->arr[i] == x)
		{
			return i;
		}
	}
	return -1;
}
void SLxgai(SL* p, int wei, leixing x)
{
	assert(p);
	assert(p->size);
	p->arr[wei] = x;
}